package com.sscaipiao.android.activity.Kuai3;

import java.util.ArrayList;
import java.util.HashMap;

import com.sscaipiao.android.R;
import com.sscaipiao.android.activity.KaijiangActivity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class Kuai3Activity extends Activity{
	ListView mKuai3ListView;
	Kuai3Adapter mKuai3DataAdapter;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kuai3_his);
		
		Button kuai3_his_button_back = (Button)findViewById(R.id.kuai3_his_button_back);
		kuai3_his_button_back.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(Kuai3Activity.this, KaijiangActivity.class);
				startActivity(intent);	
			}
		});
		mKuai3ListView = (ListView)findViewById(R.id.kuai3_his_listView);
		mKuai3DataAdapter = new Kuai3Adapter();
		ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> map;
		for (int i =1; i < 4; i++) {
			map= new HashMap<String,String>();
			map.put("jiqi", "第"+i+"期");
			map.put("riqi", "2013-11-1"+i);
			map.put("xingqi", "星期"+i);
			list.add(map);
		}
		mKuai3DataAdapter.setData(list);
		mKuai3ListView.setAdapter(mKuai3DataAdapter);
}
	class Kuai3Adapter extends BaseAdapter {
		private static final int id = 0;
		ArrayList<HashMap<String,String>> mItemList;
		Kuai3Adapter() {
			// data
		}
		
		public void setData(ArrayList<HashMap<String, String>> data) {
			mItemList = data;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mItemList.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mItemList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			Holder holder ;
			if (convertView == null) {
				convertView = View.inflate(Kuai3Activity.this, R.layout.kuai3_his_item, null);
				holder = new Holder(); 
				holder.jiqi = (TextView)convertView.findViewById(R.id.kuai3_his_text1);

				holder.riqi = (TextView)convertView.findViewById(R.id.kuai3_his_text2);
				holder.shijian = (TextView)convertView.findViewById(R.id.kuai3_his_text3);

				convertView.setTag(holder);
			}
			else {
				holder = (Holder)convertView.getTag();
//				convertView.findViewById(id) 
//					mItemList.get(0);
	
			}
			HashMap<String, String> item = mItemList.get(position);
			holder.jiqi.setText(item.get("jiqi"));//"第XXXX期"
			holder.riqi.setText(item.get("riqi"));//"2013-11-10"
			holder.shijian.setText(item.get("shijian"));//"星期天"

//			//设置标题
//			convertView.findViewById(id).setTitle();
//			// 设置第几期
			return convertView;
		}
		class Holder {
			TextView jiqi;
			TextView riqi;
			TextView shijian;
		}
		
	}
}